﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for clsKetQuaBaithi
/// </summary>
public class clsKetQuaBaithi
{
    DataClassesDataContext kqt = new DataClassesDataContext();
	public clsKetQuaBaithi()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void ThemBaiThi(string madt, string mabt, string ngaythi, string tenbt,string masv)
    {
        
        tbl_BAITHI baithi = new tbl_BAITHI();
        //DateTime dt = new DateTime();
        baithi.MaBT = mabt;
        baithi.MaDT = madt;
        baithi.NgayThi = ngaythi;
        baithi.TenBaiThi = tenbt;
        baithi.MaSV = masv;
        //baithi.SoCauDung = socaudung;
        //baithi.Diem = diem;

        kqt.tbl_BAITHIs.InsertOnSubmit(baithi);
        kqt.SubmitChanges();
                            
                      
    }
    public void KetQua(string mabt,string madt)
    {
        var listcaudung = from p in kqt.tbl_NGANHANGCAUHOIs
                          from q in kqt.tbl_CHITIETBAITHIs
                          where p.DADUNG == q.Traloi && q.MaBT==mabt
                          select p.DADUNG;
        int socaudung = listcaudung.Count();
        int socauhoi = (from p in kqt.tbl_DETHIs
                        from q in kqt.tbl_QUYTACDETHIs
                        where q.MaQT == p.MaQT && p.MaDT == madt
                        select q.SoCH).Single();
        float diem = 10 * socaudung / socauhoi;

        var kqthi = (from p in kqt.tbl_BAITHIs
                     where p.MaBT == mabt
                     select p).Single();
        kqthi.Socaudung = socaudung;
        kqthi.Diem = diem;
        kqt.SubmitChanges();
 
    }

}
